package com.wuji1626.spark.rdd.action

import org.apache.spark.{SparkConf, SparkContext}

object RDD_Action_foreach_Sample {

  def main(args: Array[String]): Unit = {

    // Step1: 准备环境
    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("Operator")
    val sc = new SparkContext(sparkConf)
    // Step2: 算子 foreach
    val rdd = sc.makeRDD(List(1, 2, 3, 4, 5, 6))

    var user = new User()

    rdd.foreach(
      num =>{
        println("age = " + (user.age + num))
      }
    )

    // Step3: 关闭环境
    sc.stop()
  }
//  class User extends Serializable   {
//    var age: Int = 30
//  }
  class User() {
  var age: Int = 30
  }
}
